package assdraw2.common;

import assdraw2.canvas.CanvasControl;
import assdraw2.coloragent.ColorControl;
import assdraw2.historyagent.HistoryControl;
import assdraw2.intermediate.control.DrawingIntermediateAgent;
import assdraw2.statusagent.StatusBarControl;
import assdraw2.toolbaragent.ToolbarControl;

public class AgentFactory {
	
	private static DrawingIntermediateAgent intermediateAgent;
	private static StatusBarControl statusBarAgent;
	private static HistoryControl historyAgent;

	public static PACAgent getAgent(int id, PACAgent parent) {
		switch(id){
			case 0:
				if(intermediateAgent == null){
					intermediateAgent = new DrawingIntermediateAgent(parent);
				}
				return intermediateAgent;
			case 1:
				if(intermediateAgent == null){
					intermediateAgent = new DrawingIntermediateAgent(parent);
				}
				return intermediateAgent;
				
			case 2:
				if(intermediateAgent == null){
					intermediateAgent = new DrawingIntermediateAgent(parent);
				}
				return intermediateAgent;

				
			case 3:
				if(statusBarAgent == null){
					statusBarAgent = new StatusBarControl(parent);
				}
				return statusBarAgent;
				

			case 4:
				if(historyAgent == null){
					historyAgent = new HistoryControl(parent);
				}
				return historyAgent;
			
		}
		return null;
	}

	public static int getId(PACAgent source) {
		if(source instanceof CanvasControl){
			return 0;
		}else if(source instanceof ToolbarControl){
			return 1;
		}else if(source instanceof ColorControl){
			return 2;
		}else if(source instanceof StatusBarControl){
			return 3;
		}else if(source instanceof HistoryControl){
			return 4;
		}
		
		return -1;
	}

}
